const { Add, Update, QueryById, QueryOne } = require('../db/dbhelper');
var { init, format } = require('../models/wechatuser');

//新增
const wechatuserAdd = function (doc) {
  return Add('hzz_wechatusers', init(doc));
}

//修改
const wechatuserUpdate = function (doc) {
  return Update('hzz_wechatusers', format(doc));
}

//修改
const wechatuserQuery = function (openid) {
  return QueryOne('hzz_wechatusers', {'openid':openid});
}

//获取是否关注
const isOfficial = async function (unionid) {
  try {
    if(unionid){
      let data= await QueryOne('hzz_wechatusers', {'unionid': unionid});
      if(data && data.fllow){
        return 1;
      }else{
        return 0;
      }
    }else{
      return 0;
    }
  } catch (error) {
    return 0;
  }
}

module.exports = {
  wechatuserAdd,
  wechatuserQuery,
  wechatuserUpdate,
  isOfficial
}